//
//  CustomSketchMapTableViewCell.m
//  AmountBody
//
//  Created by smm on 2018/1/11.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "CustomSketchMapTableViewCell.h"

@implementation CustomSketchMapTableViewCell
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self initSubViews];
    }
    return self;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initSubViews];
    }
    return self;
}

-(void)initSubViews
{
    _nameLabel = [[UILabel alloc]init];
    [self addSubview:_nameLabel];
    _valueLabel = [[UILabel alloc]init];
    [self addSubview:_valueLabel];
    _lineImage= [[UIImageView alloc]init];
    [self addSubview:_lineImage];
    _showImage = [[UIImageView alloc]init];
    [self addSubview:_showImage];
    _fd_lineImage = [[UIImageView alloc]init];
    [self addSubview:_fd_lineImage];
    _fd_titleLabel = [[UILabel alloc]init];
    [self addSubview:_fd_titleLabel];
    _fd_contentLabel = [[UILabel alloc]init];
    [self addSubview:_fd_contentLabel];
    
}

-(void)setCellWithNull
{
    _nameLabel.hidden = YES;
    _valueLabel.hidden = YES;
    _lineImage.hidden = YES;
    _showImage.hidden = YES;
    _fd_lineImage.hidden = YES;
    _fd_titleLabel.hidden = YES;
    _fd_contentLabel.hidden = YES;
}

-(void)setCellWithModel:(EssentialModel*)model andModel:(EssentialModel*)model2
{
    [self setCellWithNull];

    CGFloat jianGe = 8;
    _nameLabel.hidden = NO;
    NSString * needStr = [NSString stringWithFormat:@"%@%@",model.name,model.value];
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:needStr];
    
    // 设置字体和设置字体的范围
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:12.0f]
                    range:NSMakeRange(0, needStr.length)];
    // 添加文字颜色
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:QianZi_color
                    range:NSMakeRange(0, needStr.length)];
    // 添加文字颜色
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:ZhongZi_Color
                    range:NSMakeRange(model.name.length, model.value.length)];
    // 设置字体和设置字体的范围
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:13.0f]
                    range:NSMakeRange(model.name.length, model.value.length)];
    
    _nameLabel.attributedText = attrStr;
    _nameLabel.numberOfLines = 0;
    CGFloat jianGeH = 10;
    //        [leftLabel sizeToFit];
//    CGFloat height = _nameLabel.frame.size.height;
    [_nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(jianGe);
        make.width.equalTo(self).multipliedBy(0.5).offset(-jianGe);
        make.top.equalTo(@(jianGeH));
//        make.bottom.equalTo(@(jianGeH));
        //            make.height.equalTo(@(height));
    }];
    
    
    needStr = [NSString stringWithFormat:@"%@%@",model2.name,model2.value];
    attrStr = [[NSMutableAttributedString alloc] initWithString:needStr];
    
    // 设置字体和设置字体的范围
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:12.0f]
                    range:NSMakeRange(0, needStr.length)];
    // 添加文字颜色
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:QianZi_color
                    range:NSMakeRange(0, needStr.length)];
    // 添加文字颜色
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:ZhongZi_Color
                    range:NSMakeRange(model2.name.length, model2.value.length)];
    // 设置字体和设置字体的范围
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:13.0f]
                    range:NSMakeRange(model2.name.length, model2.value.length)];
    
//    _valueLabel = [[UILabel alloc]init];
//    [self addSubview:_valueLabel];
    _valueLabel.hidden = NO;
    _valueLabel.attributedText = attrStr;
    _valueLabel.numberOfLines = 0;
    //        [rightLabel sizeToFit];
//    height = _valueLabel.frame.size.height;
   
    [_valueLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-jianGe);
        make.width.equalTo(self).multipliedBy(0.5).offset(-jianGe);
        make.top.equalTo(@(jianGeH));
        make.bottom.equalTo(self).offset(-jianGeH);
    }];
    if (self.hasLine) {
//        _lineImage = [[UIImageView alloc]init];
//        [self addSubview:_lineImage];
        _lineImage.hidden = NO;
        _lineImage.image = [UIImage imageNamed:@"quline"];
        [_lineImage mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(jianGe);
            make.right.equalTo(self).offset(-jianGe);
            make.top.equalTo(_valueLabel.mas_bottom).offset(jianGeH-1);
            make.height.equalTo(@(1));
//            make.bottom.equalTo(self);
        }];
    }else{
        
    }
    
    
}

-(void)setCellWithImage:(NSString *)imageStr
{
     [self setCellWithNull];
    CGFloat jianGe = 8;
//    for (UIView * view in self.subviews) {
//        [view removeFromSuperview];
//    }
//    _showImage = [[UIImageView alloc]init];
//    [self addSubview:_showImage];
    _showImage.hidden = NO;
    _showImage.image = [UIImage imageNamed:@"l_photo"];
    _showImage.contentMode = UIViewContentModeScaleAspectFit;
    [_showImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self).with.offset(jianGe);
        make.right.equalTo(self).with.offset(-jianGe);
        make.height.equalTo(self.mas_width).with.offset(-jianGe*2).multipliedBy(104./183.);
        make.top.equalTo(self).with.offset(10);
        make.bottom.equalTo(self);
    }];
}

-(void)setCellWithContent:(NSString *)contentStr andName:(NSString*)nameStr
{
     [self setCellWithNull];
    CGFloat jianGe = 8;
//    for (UIView * view in self.subviews) {
//        [view removeFromSuperview];
//    }
//    _fd_lineImage = [[UIImageView alloc]init];
//    [self addSubview:_fd_lineImage];
    _fd_lineImage.hidden = NO;
    [_fd_lineImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).with.offset(jianGe);
        make.right.equalTo(self).with.offset(-jianGe);
        make.top.equalTo(self).with.offset(15);
        make.height.equalTo(@(1));
    }];
    _fd_lineImage.image = [UIImage imageNamed:@"duanline"];
//    _fd_titleLabel = [[UILabel alloc]init];
//    [self addSubview:_fd_titleLabel];
    _fd_titleLabel.hidden = NO;
    _fd_titleLabel.text  = nameStr;
    _fd_titleLabel.textColor = ShenZi_Color;
    _fd_titleLabel.font = Cell_Big_Font;
    [_fd_titleLabel sizeToFit];
    [_fd_titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.height.equalTo(@(Nomal_Label_H));
        make.width.equalTo(_fd_titleLabel);
        make.centerY.equalTo(_fd_lineImage);
        
    }];
//    _fd_contentLabel = [[UILabel alloc]init];
//    [self addSubview:_fd_contentLabel];
    _fd_contentLabel.hidden = NO;
    _fd_contentLabel.text = contentStr;
    _fd_contentLabel.numberOfLines = 0;
    _fd_contentLabel.font = Cell_Little_Font;
    _fd_contentLabel.textColor = QianZi_color;
    
    [_fd_contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_fd_titleLabel.mas_bottom).offset(5);
        make.left.equalTo(self).with.offset(jianGe);
        make.right.equalTo(self).with.offset(-jianGe);
        make.bottom.equalTo(self).offset(-10);
        //        make.height.equalTo(@(height));
        
    }];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
